/*
 * 文件名：CustAnalysisAction.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：Administrator
 * 修改时间：2013-2-21
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.customer.custanalysis.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.wootide.cms.common.Constants;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.Result;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.customer.custanalysis.pojo.CustomerDetail;
import com.wootide.cms.service.customer.custanalysis.service.CustAnalysisService;
import com.wootide.cms.service.reservation.bookinfo.pojo.BookOrderInfo;
import com.wootide.cms.sys.common.action.BaseAction;

/**
 * 〈一句话功能简述〉客户消费分析<br>
 *  1.分析数据来源：客户消费记录；
 * 〈功能详细描述〉通过对客户个人的消费记录，分析该客户的消费偏好。
 * @author Administrator
 * @version 2013-2-21
 * @see CustAnalysisAction
 * @since
 */
public class CustAnalysisAction extends BaseAction implements
        ServletRequestAware
{
    /**
     * 意义，目的和功能，以及被用到的地方<br>
     */
    private static final long serialVersionUID = 4750047225598680053L;
    
    //客户信息
    private BookOrderInfo bookOrderInfo;
    
    //日志
    private RunLog runLog;
    
    //用户信息系业务层实例
    private CustAnalysisService custAnalysisService;
    
    //分页信息
    private Page page;
    
    //查询条件
    private QueryCondition queryConditon;
    
    // Http请求对象
    private HttpServletRequest request;
    
    // 客户结果集
    @SuppressWarnings("unchecked")
    private List results;
    
    //返回消息
    private String message;
    
    // 是否操作成功
    private Integer actResult = Constants.ACTRESULT_DEF;
    
    // 客户ID
    private Integer innerIndex;
    
    //客户ID集合
    private Integer[] innerIndexs;
    
    //明细
    private CustomerDetail customerDetail;
    
    public String doQuery()
    {
        try
        {
            // 如果从菜单进入，即在没有分页信息的情况下，则默认进入首页
            if (null == page)
            {
                page = new Page();
                page.setCurPage(1);
            }
            
            // 调用而业务层进行分页查询
            queryConditon = null == queryConditon ? new QueryCondition()
                    : queryConditon;
            queryConditon.setObjClass(BookOrderInfo.class);
            Result result = custAnalysisService.queryForPages(page,
                    queryConditon);
            
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                QueryResults queryResults = (QueryResults)result.getResultPojo();
                // 获取服务代码结果集
                runLog.debug(queryResults);
                results = queryResults.getResults();
                // 获取分页信息
                page = queryResults.getPage();
                
                // 跳转到分页页面
                return SUCCESS;
            }
            else
            {
                message = getText(Constants.MESSAGE_PREFIX + resultCode);
                return ERROR;
            }
            
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
    }
    
    public String doDetail()
    {
        try
        {
            customerDetail = null != null ? customerDetail
                    : new CustomerDetail();
            Result result = custAnalysisService.getCustomerDetail(customerDetail,
                    innerIndex);
            int resultCode = result.getResultCode();
            if (ErrorCodes.ERRORCODE_SUCC == resultCode)
            {
                return SUCCESS;
            }
            else
            {
                return ERROR;
            }
        }
        catch (Exception e)
        {
            runLog.error("Unknow Error!", e, request);
            message = getText(Constants.MESSAGE_PREFIX
                    + ErrorCodes.ERRORCODE_UNKNOW);
            return ERROR;
        }
        
    }
    
    public BookOrderInfo getBookOrderInfo()
    {
        return bookOrderInfo;
    }
    
    public void setBookOrderInfo(BookOrderInfo bookOrderInfo)
    {
        this.bookOrderInfo = bookOrderInfo;
    }
    
    public RunLog getRunLog()
    {
        return runLog;
    }
    
    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }
    
    public CustAnalysisService getCustAnalysisService()
    {
        return custAnalysisService;
    }
    
    public void setCustAnalysisService(CustAnalysisService custAnalysisService)
    {
        this.custAnalysisService = custAnalysisService;
    }
    
    public Page getPage()
    {
        return page;
    }
    
    public void setPage(Page page)
    {
        this.page = page;
    }
    
    public QueryCondition getQueryConditon()
    {
        return queryConditon;
    }
    
    public void setQueryConditon(QueryCondition queryConditon)
    {
        this.queryConditon = queryConditon;
    }
    
    public HttpServletRequest getRequest()
    {
        return request;
    }
    
    public void setRequest(HttpServletRequest request)
    {
        this.request = request;
    }
    
    @SuppressWarnings("unchecked")
    public List getResults()
    {
        return results;
    }
    
    @SuppressWarnings("unchecked")
    public void setResults(List results)
    {
        this.results = results;
    }
    
    public String getMessage()
    {
        return message;
    }
    
    public void setMessage(String message)
    {
        this.message = message;
    }
    
    public Integer getActResult()
    {
        return actResult;
    }
    
    public void setActResult(Integer actResult)
    {
        this.actResult = actResult;
    }
    
    public Integer getInnerIndex()
    {
        return innerIndex;
    }
    
    public void setInnerIndex(Integer innerIndex)
    {
        this.innerIndex = innerIndex;
    }
    
    public Integer[] getInnerIndexs()
    {
        return innerIndexs;
    }
    
    public void setInnerIndexs(Integer[] innerIndexs)
    {
        this.innerIndexs = innerIndexs;
    }
    
    @Override
    public void setServletRequest(HttpServletRequest request)
    {
        this.request = request;
    }
    
    public CustomerDetail getCustomerDetail()
    {
        return customerDetail;
    }
    
    public void setCustomerDetail(CustomerDetail customerDetail)
    {
        this.customerDetail = customerDetail;
    }
}
